package com.regentsoft.cloudback.enterpriseAdmin.util;

import com.regentsoft.cloudback.enterpriseAdmin.entity.CompanyAdminModel;
import com.regentsoft.cloudback.util.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by work on 2017/11/27.
 *
 * @author lumr
 */
@Component
public class AdminTokenManager {
    private final RedisClient client;

    private final String REDIS_KEY = "ADMIN_TOKEN_";

    private final int seconds = 36000;

    @Autowired
    public AdminTokenManager(RedisClient client) {
        this.client = client;
    }

    public boolean exists(String key){
        return client.exists(formatKey(key));
    }

    public String set(String key,CompanyAdminModel model){
        return client.set(formatKey(key),seconds,model);
    }

    public CompanyAdminModel get(String key){
        return client.get(formatKey(key),CompanyAdminModel.class);
    }

    private String formatKey(String key){
        return REDIS_KEY.concat(key);
    }
}
